import crypto from 'crypto-js';
import { Base64 } from 'js-base64';

// 计算签名。
function computeSignature(accessKeySecret, canonicalString) {
  return crypto.enc.Base64.stringify(crypto.HmacSHA1(canonicalString, accessKeySecret));
}

const date = new Date();
date.setHours(date.getHours() + 1);
const policyText = {
  expiration: date.toISOString(), // 设置policy过期时间。
  conditions: [
    // 限制上传大小。
    ["content-length-range", 0, 1024 * 1024 * 1024],
  ],
};

export  function getFormDataParams() {
  const policy = Base64.encode(JSON.stringify(policyText)) // policy必须为base64的string。
  const signature = computeSignature('eEBn8XSwPrDwDPkKcLR3SGvuV3aEK8AmLo5jQtcgAvV', policy)
  const formData = {
    OSSAccessKeyId:  "STS.NSvst8iy8w1XzWk7RL5BXmYhg",
    signature,
    policy,
    'x-oss-security-token':  "CAIS7AF1q6Ft5B2yfSjIr5DDOM6MhKYZwPOzeHHa01IZOc10gpzDhTz2IHFJfHltBewdsfQ3nmFU7/sYlqx6T55OSBQWnx3rPM0Fnzm6aq/t5uaXj9Vd+rDHdEGXDxnkprywB8zyUNLafNq0dlnAjVUd6LDmdDKkLTfHWN/z/vwBVNkMWRSiZjdrHcpfIhAYyPUXLnzML/2gQHWI6yjydBM05lcn0z0guPThmZHMskrk4QekmrNPlePYOYO5asRgBpB7Xuqu0fZ+Hqi7i38Ns0gXqPst0/wco2ab54zHGTlX51CIKe3S7s2/us3iyxCacRqAAQ/UO+dKkfDbbJTFXefZxj61bPynmgB/Z0XZVpTbp6RvxzGs5aMT57CoLKtUSSZV7zA5pVLDvfl3NcCKZLXOWNBLWl4iHgkIZLsdimFvsbBC8DfBDRrgfOlBVCuoFTKm+4dK85i9IaPDN4uizhTixnkX6zkk0fCkURQ0jTLwHzLsIAA=",
  }
  return formData
}